﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace StockMarketTool.Converter
{
    public class IsLastItemInContainerConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                DependencyObject item = (DependencyObject)value;
                ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(item);
                return ic.ItemContainerGenerator.IndexFromContainer(item) == ic.Items.Count - 1;
            }
            catch
            {
                return false;
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }

    }
}
